<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>example</title>
    <script src="../../vue.js/vue.js"></script>
  </head>

  <body>
    <div id="example">
      <p>Original message: "{{ message }}"</p>
      <p>Computed reversed message: "{{ reversedMessage }}"</p>
    </div>

    <script>
      var vm = new Vue({
        el: "#example",
        data: {
          message: "Hello",
        },
        computed: {
          // 计算属性的 getter
          reversedMessage: function () {
            // `this` 指向 vm 实例
            return this.message.split("").reverse().join("");
          },
        },
      });

      console.log(vm.reversedMessage); // => 'olleH'
      vm.message = "Goodbye";
      console.log(vm.reversedMessage); // => 'eybdooG'
    </script>
  </body>
</html>
